package com.urbane.banner;

import lombok.Getter;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.io.PrintStream;
import java.time.Duration;

@Getter
public class CustomBannerRunListener implements SpringApplicationRunListener {

//    private final SpringApplication application;
//    private final String[] args;
//
//    // 必须有这个构造函数
//    public CustomBannerRunListener(SpringApplication application, String[] args) {
//        this.application = application;
//        this.args = args;
//        // 关闭 Spring Boot 默认 Banner
//        application.setBannerMode(Banner.Mode.OFF);
//    }


    @Override
    public void starting(ConfigurableBootstrapContext bootstrapContext) {
        System.out.println("CustomBannerRunListener.starting()");
    }

    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
        System.out.println("CustomBannerRunListener.environmentPrepared()");
    }


    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        SpringApplicationRunListener.super.contextPrepared(context);
        System.out.println("CustomBannerRunListener.contextPrepared()");
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        SpringApplicationRunListener.super.contextLoaded(context);
        System.out.println("CustomBannerRunListener.contextLoaded()");
    }

    @Override
    public void started(ConfigurableApplicationContext context, Duration timeTaken) {
        SpringApplicationRunListener.super.started(context, timeTaken);
        System.out.println("CustomBannerRunListener.started()");
    }

    @Override
    public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
        SpringApplicationRunListener.super.ready(context, timeTaken);
        System.out.println("CustomBannerRunListener.ready()");
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        SpringApplicationRunListener.super.failed(context, exception);
        System.out.println("CustomBannerRunListener.failed()");
    }
}